/**
 * @Author: douxuefeng
 * @Date: 2020/11/19 上午9:13
 * @File: config
 * @Desc:
 */
package config

import (
	"flag"
	"gopkg.in/yaml.v3"
	"gorm.io/gorm/logger"
	"io/ioutil"
)
var config *Config
type Config struct {
	AppName string `yaml:"AppName"`
	Prod bool `yaml:"Prod"`
	BaseUrl string `yaml:"BaseUrl"`
	Addr string `yaml:"Addr"`
	JwtSecret string `yaml:"JwtSecret"`
	Page int `yaml:"Page"`
	Logs string `yaml:"Logs"`
	MySql struct{
		Host string `yaml:"Host"`
		DataBase string `yaml:"DataBase"`
		UserName string `yaml:"UserName"`
		Password string `yaml:"Password"`
		Prefix string `yaml:"Prefix"`
		LogMode logger.LogLevel `yaml:"LogMode"`
		MaxIdle int `yaml:"MaxIdle"`
		MaxOpen int `yaml:"MaxOpen"`
	} `yaml:"MySql"`
	Redis struct{
		Host string `yaml:"Host"`
		DataBase int `yaml:"DataBase"`
		Password string `yaml:"Password"`
		MaxIdle int `yaml:"MaxIdle"`
		MaxActive int `yaml:"MaxActive"`
		IdleTimeout int `yaml:"IdleTimeout"`
	} `yaml:"Redis"`

	WechatOffice struct{
		AppId string `yaml:"AppId"`
		AppSecret string `yaml:"AppSecret"`
		Token string `yaml:"Token"`
	} `yaml:"WechatOffice"`
}

func GetConfig() *Config {
	return config
}
func init()  {
	var (
		err error
		configFile = flag.String("config","./config/config.yaml","配置文件")
	)
	flag.Parse()
	f, err := ioutil.ReadFile(*configFile)
	if err != nil {
		panic(err)
	}
	err = yaml.Unmarshal(f, &config)
	if err != nil {
		panic(err)
	}
}
